package com.boyinet.activation.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.boyinet.activation.entity.Order;
import com.boyinet.activation.mapper.OrderMapper;
import com.boyinet.activation.service.OrderService;
import com.boyinet.activation.vo.OrderVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lengchunyun
 * @since 2020-12-29
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Resource
    OrderMapper orderMapper;

    @Override
    public Page<Order> listByPage(OrderVO condition) {
        LambdaQueryWrapper<Order> queryWrapper = new QueryWrapper<Order>().lambda()
                .like(StringUtils.isNotBlank(condition.getClientName()), Order::getCompanyName, condition.getClientName())
                .like(StringUtils.isNotBlank(condition.getAddress()), Order::getAddress, condition.getAddress())
                .between(Objects.nonNull(condition.getMinCreateTime()), Order::getCreateTime, condition.getMinCreateTime(), condition.getMaxCreateTime())
                .between(Objects.nonNull(condition.getMinUseTime()), Order::getUseTime, condition.getMinUseTime(), condition.getMaxUseTime());
        return orderMapper.selectPage(new Page<>(condition.getPage(), condition.getLimit()), queryWrapper);
    }
}
